<!DOCTYPE html>
            
<HTML>
<HEAD>
<meta name="booktitle" content="Developing Applications With Objective Caml" >
 <meta charset="ISO-8859-1"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<META name="GENERATOR" content="hevea 1.05-7 of 2000-02-24">
<META NAME="Author" CONTENT="Christian.Queinnec@lip6.fr">
<LINK rel=stylesheet type="text/css" href="videoc-ocda.css">
<script language="JavaScript" src="videoc.js"><!--
//--></script>
<TITLE>
 The Internet
</TITLE>
</HEAD>
<BODY class="regularBody">
<A HREF="book-ora184.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora186.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2> The Internet</H2><A NAME="sec-Internet"></A>The Internet is a network of networks.
Their interconnection is organized as a hierarchy of domains, 
subdomains, and so on, through interfaces. An interface 
is the hardware in a computer that allows it to be connected
(typically, an Ethernet card). Some computers may have 
several interfaces. Each interface has a unique IP address
that respects, in general, the interconnection hierarchy.
Message routing is also organized hierarchically: from domain
to domain; then from domain to subdomains, and so on, until 
a message reaches its destination interface. Besides their 
interface addresses, computers usually also have a name, 
as do domains and subdomains. Some machines have a particular 
role in the network:
<DL COMPACT=compact>
<DT>
bridges<DD> connect one network to another;

<DT>routers<DD> use their knowledge of the topology of the Internet 
to route data;

<DT>name servers<DD> track the correspondence between machine names 
and network addresses.
</DL>
The purpose of the Internet protocol (i.e., of the IP) 
is to make the network of networks into a single entity.
This is why one can speak of <B>the</B> Internet. 
Any two machines connected via the Internet can communicate.
Many kinds of machines and systems coexist on the Internet. 
All of them use IP protocols and most of them, the UDP and 
TCP layers. <BR>
<BR>
The different protocols and services used by the Internet are 
described in RFC's (Requests For Comments), 
which can be found on the Jussieu mirror site:


<H3> Link </H3> <HR>

<A HREF="ftp://ftp.lip6.fr/pub/rfc">ftp://ftp.lip6.fr/pub/rfc</A>


<HR>

<BR>
<BR>

<H4> Internet Protocols and Services</H4>The unit of transfer used by the IP protocol is the 
<EM>datagram</EM> or <EM>packet</EM>. This protocol in unreliable: 
it does not assure proper order, safe arrival, or non-duplication
of transmitted packets. It only deals with correct routing of 
packets and signaling of errors when a packet is unable to 
reach its destination. Addresses are coded into 32 bits 
in the current version of the protocol: IPv4. These 32 bits 
are divided into four fields, each containing values between
0 and 255. IP addresses are written with the four fields
separated by periods, for example: <CODE>132.227.60.30</CODE>.<BR>
<BR>
The IP protocol is in the midst of an important change
made necessary by the exhaustion of address space and the 
growing complexity of routing problems due to the expansion of the
Internet. The new version of the IP protocol is 
IPv6, which is described in [<A HREF="book-ora214.html#IPv6"><CITE>Hui97</CITE></A>].<BR>
<BR>
Above IP, two protocols allow higher-level transmissions:
UDP (User Datagram Protocol, and TCP (Transfer Control
Protocol). These two protocols use IP for communication
between machines, also allowing communication between applications
(or programs) running on those machines. They deal with correct transmission 
of information, independent of contents. The identification of 
applications on a machine is done via a port number.<BR>
<BR>
UDP is a connectionless, unreliable protocol: it is to 
applications as IP is to interfaces. TCP is 
a connection-oriented, reliable protocol: it manages acknowledgement, 
retransmission, and ordering of packets. Further, it is capable 
of optimizing transmission by a windowing technique.<BR>
<BR>
The standard services (applications) of the Internet most often
use the client-server model. The server manages requests by clients,
offering them a specific service. There is an asymmetry between 
client and server. The services establish high-level protocols for 
keeping track of transmitted contents. Among the standard services, we note:
<UL>
<LI>
 FTP (File Transfer Protocol);

<LI> TELNET (Terminal Protocol);

<LI> SMTP (Simple Mail Transfer Protocol);

<LI> HTTP (Hypertext Transfer Protocol).
</UL>Other services use the client-server model:
<UL>
<LI>
 NFS (Network File System);

<LI> X-Windows
<LI> Unix services: rlogin, rwho ...</UL>
Communication between applications takes place via sockets.
Sockets allow communication between processes residing on possibly different
machines. Different processes can read and write to sockets.<BR>
<BR>
<A NAME="toc272"></A>
<H3> The <TT>Unix</TT> Module and IP Addressing</H3>
The <TT>Unix</TT> library defines the abstract type <I>inet_addr</I>
<A NAME="@fonctions461"></A>
representing Internet addresses, as well as two conversion functions
between an internal representation of addresses and strings:


<PRE><BR># Unix.inet_addr_of_string<CODE> </CODE>;;<BR><CODE>- : string -&gt; Unix.inet_addr = &lt;fun&gt;</CODE><BR># Unix.string_of_inet_addr<CODE> </CODE>;;<BR><CODE>- : Unix.inet_addr -&gt; string = &lt;fun&gt;</CODE><BR>

</PRE>

<A NAME="@fonctions462"></A>
<A NAME="@fonctions463"></A><BR>
<BR>
In applications, Internet addresses and port numbers for 
services (or service numbers) are often replaced by names.
The correspondence between names and address or number is
managed using databases. The <TT>Unix</TT> library 
provides functions to request data from these databases and 
provides datatypes to allow storage of the obtained information.
We briefly describe these functions below.<BR>
<BR>

<H5> Address tables.</H5>
The table of addresses (hosts database) contains 
the assocation between machine name(s) and interface address(es).
The structure 
of entries in the address table is represented by:


<PRE><BR># <B>type</B><CODE> </CODE>host_entry<CODE> </CODE><CODE>=</CODE><BR><CODE> </CODE><CODE> </CODE><CODE> </CODE>{<CODE> </CODE>h_name<CODE> </CODE><CODE>:</CODE><CODE> </CODE>string;<BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>h_aliases<CODE> </CODE><CODE>:</CODE><CODE> </CODE>string<CODE> </CODE>array;<BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>h_addrtype<CODE> </CODE><CODE>:</CODE><CODE> </CODE>socket_domain;<BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>h_addr_list<CODE> </CODE><CODE>:</CODE><CODE> </CODE>inet_addr<CODE> </CODE>array<CODE> </CODE>}<CODE> </CODE>;;<BR>

</PRE>

<A NAME="@fonctions464"></A>
The first two fields contain the machine name and its aliases; 
the third contains the address type (see page
<A HREF="book-ora186.html#sec-socket">??</A>); the last contains a list of 
machine addresses.<BR>
<BR>
A machine name is obtained by using the function:


<PRE><BR># Unix.gethostname<CODE> </CODE>;;<BR><CODE>- : unit -&gt; string = &lt;fun&gt;</CODE><BR># <B>let</B><CODE> </CODE>my_name<CODE> </CODE><CODE>=</CODE><CODE> </CODE>Unix.gethostname()<CODE> </CODE>;;<BR><CODE>val my_name : string = "estephe.inria.fr"</CODE><BR>

</PRE>

<A NAME="@fonctions465"></A><BR>
<BR>
The functions that query the address table 
require an entry, either the name or the machine address.


<PRE><BR># Unix.gethostbyname<CODE> </CODE>;;<BR><CODE>- : string -&gt; Unix.host_entry = &lt;fun&gt;</CODE><BR># Unix.gethostbyaddr<CODE> </CODE>;;<BR><CODE>- : Unix.inet_addr -&gt; Unix.host_entry = &lt;fun&gt;</CODE><BR># <B>let</B><CODE> </CODE>my_entry_byname<CODE> </CODE><CODE>=</CODE><CODE> </CODE>Unix.gethostbyname<CODE> </CODE>my_name<CODE> </CODE>;;<BR><CODE>val my_entry_byname : Unix.host_entry =</CODE><BR><CODE>  {Unix.h_name="estephe.inria.fr"; Unix.h_aliases=[|"estephe"|];</CODE><BR><CODE>   Unix.h_addrtype=Unix.PF_INET; Unix.h_addr_list=[|&lt;abstr&gt;|]}</CODE><BR># <B>let</B><CODE> </CODE>my_addr<CODE> </CODE><CODE>=</CODE><CODE> </CODE>my_entry_byname<CODE>.</CODE>Unix.h_addr_list<CODE>.</CODE><TT>(</TT><CODE>0</CODE><TT>)</TT><CODE> </CODE>;;<BR><CODE>val my_addr : Unix.inet_addr = &lt;abstr&gt;</CODE><BR><BR># <B>let</B><CODE> </CODE>my_entry_byaddr<CODE> </CODE><CODE>=</CODE><CODE> </CODE>Unix.gethostbyaddr<CODE> </CODE>my_addr<CODE> </CODE>;;<BR><CODE>val my_entry_byaddr : Unix.host_entry =</CODE><BR><CODE>  {Unix.h_name="estephe.inria.fr"; Unix.h_aliases=[|"estephe"|];</CODE><BR><CODE>   Unix.h_addrtype=Unix.PF_INET; Unix.h_addr_list=[|&lt;abstr&gt;|]}</CODE><BR><BR># <B>let</B><CODE> </CODE>my_full_name<CODE> </CODE><CODE>=</CODE><CODE> </CODE>my_entry_byaddr<CODE>.</CODE>Unix.h_name<CODE> </CODE>;;<BR><CODE>val my_full_name : string = "estephe.inria.fr"</CODE><BR>

</PRE>

<A NAME="@fonctions466"></A>
<A NAME="@fonctions467"></A>
<A NAME="val-my-addr"></A>
These functions raise the <TT>Not_found</TT> exception in case 
the request fails.<BR>
<BR>

<H5> Table of services.</H5>
The table of services contains the correspondence 
between service names and port numbers. 
The majority of Internet services are 
standardized. The structure of entries in 
the table of services is:


<PRE><BR># <B>type</B><CODE> </CODE>service_entry<CODE> </CODE><CODE>=</CODE><BR><CODE> </CODE><CODE> </CODE><CODE> </CODE>{<CODE> </CODE>s_name<CODE> </CODE><CODE>:</CODE><CODE> </CODE>string;<BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>s_aliases<CODE> </CODE><CODE>:</CODE><CODE> </CODE>string<CODE> </CODE>array;<BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>s_port<CODE> </CODE><CODE>:</CODE><CODE> </CODE>int;<BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>s_proto<CODE> </CODE><CODE>:</CODE><CODE> </CODE>string<CODE> </CODE>}<CODE> </CODE>;;<BR>

</PRE>

<A NAME="@fonctions468"></A>
The first two fields are the service name and its eventual
aliases; the third field contains the port number; the last field
contains the name of the protocol used.<BR>
<BR>
A service is in fact characterized by its 
port number and the underlying protocol.
The query functions are:
<A NAME="@fonctions469"></A>
<A NAME="@fonctions470"></A>


<PRE><BR># Unix.getservbyname<CODE> </CODE>;;<BR><CODE>- : string -&gt; string -&gt; Unix.service_entry = &lt;fun&gt;</CODE><BR># Unix.getservbyport<CODE> </CODE>;;<BR><CODE>- : int -&gt; string -&gt; Unix.service_entry = &lt;fun&gt;</CODE><BR># Unix.getservbyport<CODE> </CODE><CODE>8</CODE><CODE>0</CODE><CODE> </CODE><CODE>"tcp"</CODE><CODE> </CODE>;;<BR><CODE>- : Unix.service_entry =</CODE><BR><CODE>{Unix.s_name="www"; Unix.s_aliases=[|"http"|]; Unix.s_port=80;</CODE><BR><CODE> Unix.s_proto="tcp"}</CODE><BR># Unix.getservbyname<CODE> </CODE><CODE>"ftp"</CODE><CODE> </CODE><CODE>"tcp"</CODE><CODE> </CODE>;;<BR><CODE>- : Unix.service_entry =</CODE><BR><CODE>{Unix.s_name="ftp"; Unix.s_aliases=[||]; Unix.s_port=21; Unix.s_proto="tcp"}</CODE><BR>

</PRE>

These functions raise the <TT>Not_found</TT> exception if 
they cannot find the service requested.<BR>
<BR>
<HR>
<A HREF="book-ora184.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora186.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
